package com.dynamixsoftware.printershare.ijs;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.InputStream;

public class IjsDriver
{
  private static final int IJS_CMD_ACK = 0;
  private static final int IJS_CMD_BEGIN_JOB = 6;
  private static final int IJS_CMD_BEGIN_PAGE = 14;
  private static final int IJS_CMD_CANCEL_JOB = 8;
  private static final int IJS_CMD_CLOSE = 5;
  private static final int IJS_CMD_END_JOB = 7;
  private static final int IJS_CMD_END_PAGE = 16;
  private static final int IJS_CMD_EXIT = 17;
  private static final int IJS_CMD_OPEN = 4;
  private static final int IJS_CMD_PING = 2;
  private static final int IJS_CMD_PONG = 3;
  private static final int IJS_CMD_SEND_DATA_BLOCK = 15;
  private static final int IJS_CMD_SET_PARAM = 12;
  private Process proc;
  public InputStream proc_es;
  private DataInputStream proc_is;
  private DataOutputStream proc_os;
  
  public IjsDriver(File paramFile, String[] paramArrayOfString)
    throws Exception
  {
    this.proc = Runtime.getRuntime().exec(paramFile.getAbsolutePath(), paramArrayOfString, paramFile.getParentFile());
    this.proc_os = new DataOutputStream(this.proc.getOutputStream());
    this.proc_is = new DataInputStream(this.proc.getInputStream());
    this.proc_es = this.proc.getErrorStream();
  }
  
  private int readCmd()
    throws Exception
  {
    int i = this.proc_is.readInt();
    int j = -8 + this.proc_is.readInt();
    if (j > 0) {
      this.proc_is.readFully(new byte[j]);
    }
    return i;
  }
  
  private int[] readCmdInt()
    throws Exception
  {
    int i = this.proc_is.readInt();
    int j = -12 + this.proc_is.readInt();
    int k = this.proc_is.readInt();
    if (j > 0) {
      this.proc_is.readFully(new byte[j]);
    }
    return new int[] { i, k };
  }
  
  private void sendCmd(int paramInt)
    throws Exception
  {
    this.proc_os.writeInt(paramInt);
    this.proc_os.writeInt(8);
    this.proc_os.flush();
  }
  
  private void sendCmdInt(int paramInt1, int paramInt2)
    throws Exception
  {
    this.proc_os.writeInt(paramInt1);
    this.proc_os.writeInt(12);
    this.proc_os.writeInt(paramInt2);
    this.proc_os.flush();
  }
  
  private void sendCmdIntInt(int paramInt1, int paramInt2, int paramInt3)
    throws Exception
  {
    this.proc_os.writeInt(paramInt1);
    this.proc_os.writeInt(16);
    this.proc_os.writeInt(paramInt2);
    this.proc_os.writeInt(paramInt3);
    this.proc_os.flush();
  }
  
  private void sendCmdIntStrStr(int paramInt1, int paramInt2, String paramString1, String paramString2)
    throws Exception
  {
    this.proc_os.writeInt(paramInt1);
    this.proc_os.writeInt(1 + (16 + paramString1.length() + paramString2.length()));
    this.proc_os.writeInt(paramInt2);
    this.proc_os.writeInt(1 + (paramString1.length() + paramString2.length()));
    this.proc_os.writeBytes(paramString1);
    this.proc_os.write(0);
    this.proc_os.writeBytes(paramString2);
    this.proc_os.flush();
  }
  
  public boolean beginJob(int paramInt)
    throws Exception
  {
    sendCmdInt(6, paramInt);
    return readCmd() == 0;
  }
  
  public boolean beginPage()
    throws Exception
  {
    sendCmd(14);
    return readCmd() == 0;
  }
  
  public boolean cancelJob(int paramInt)
    throws Exception
  {
    sendCmdInt(8, paramInt);
    return readCmd() == 0;
  }
  
  public boolean close()
    throws Exception
  {
    sendCmd(5);
    return readCmd() == 0;
  }
  
  public boolean connect()
    throws Exception
  {
    this.proc_os.writeBytes("IJS\nüv1\n");
    this.proc_os.flush();
    if (("IJS".equals(this.proc_is.readLine())) && (this.proc_is.read() == 171) && ("v1".equals(this.proc_is.readLine())))
    {
      sendCmdInt(2, 30);
      int[] arrayOfInt = readCmdInt();
      if ((arrayOfInt[0] == 3) && (arrayOfInt[1] >= 30)) {
        return true;
      }
    }
    terminate();
    return false;
  }
  
  public int disconnect()
    throws Exception
  {
    sendCmd(17);
    return this.proc.waitFor();
  }
  
  public boolean endJob(int paramInt)
    throws Exception
  {
    sendCmdInt(7, paramInt);
    return readCmd() == 0;
  }
  
  public boolean endPage()
    throws Exception
  {
    sendCmd(16);
    return readCmd() == 0;
  }
  
  public boolean open()
    throws Exception
  {
    sendCmd(4);
    return readCmd() == 0;
  }
  
  public boolean sendDataBlock(int paramInt1, byte[] paramArrayOfByte, int paramInt2, int paramInt3)
    throws Exception
  {
    sendCmdIntInt(15, paramInt1, paramInt3);
    this.proc_os.write(paramArrayOfByte, paramInt2, paramInt3);
    this.proc_os.flush();
    return readCmd() == 0;
  }
  
  public boolean setParam(int paramInt, String paramString1, String paramString2)
    throws Exception
  {
    sendCmdIntStrStr(12, paramInt, paramString1, paramString2);
    return readCmd() == 0;
  }
  
  public void terminate()
    throws Exception
  {
    this.proc.destroy();
    this.proc = null;
  }
}


/* Location:           C:\Users\Admin\Desktop\Decompiler\JAD\jd-gui-0.3.6.windows\classes_dex2jar.jar
 * Qualified Name:     com.dynamixsoftware.printershare.ijs.IjsDriver
 * JD-Core Version:    0.7.0.1
 */